const MyPromise = require("./MyPromise3")

new MyPromise(
    (resolve, reject) => {
        setTimeout(() => {
            Math.random() > 0 ? resolve("data0") : reject(new Error("一张好人卡"));
        }, 2000);
    }
)
.then(
    data => {
        console.log("then1:data=",data)
        return "data from then1"
        // throw new Error("err from then1")
    }
)
.then(
    data => {
        console.log("then2:data=",data)
        return MyPromise.resolve("data from then2")
    }
)
.then(
    data => {
        console.log("then3:data=",data)
        return new MyPromise(
            (resolve,reject) => setTimeout(() => {
                resolve("data from then3")
                // reject("err from then3")
            }, 2000)
        )
    }
)
.then(
    data => console.log("then4:data=",data)
)
.catch(
    err => {
        console.log("catch1:err=",err)
        return "data from catch1"
    }
)
.catch(
    err => console.log("catch2:err=",err)
)
.then(
    data => console.log("then5:data=",data)
)
.finally(
    ()=>console.log("finally:game over!")
)